package main

import (
	"emicro_test/emicro_9/grpc_server/mail/common"
	"emicro_test/emicro_9/grpc_server/mail/handler"
	"emicro_test/emicro_9/grpc_server/mail/lib/mq"
	pb "emicro_test/emicro_9/grpc_server/mail/pbfile"
	"emicro_test/emicro_9/grpc_server/mail/wrapper"
	"fmt"
	"github.com/asim/go-micro/v3"
	"github.com/asim/go-micro/v3/registry"
	"github.com/go-micro/plugins/v3/registry/consul"
)


func main(){
	service := common.NewService()

	//服务注册
	consulRegis := consul.NewRegistry( func(options *registry.Options){
		addr := common.Config.String("consul_addr")
		port, _ := common.Config.Int("consul_port")
		addrs := fmt.Sprintf("%v:%d", addr, port)
		options.Addrs = []string{
			addrs,
		}
	})

	service.Service = micro.NewService(
		micro.Name(common.ServerName),
		micro.Registry(consulRegis),
		micro.WrapHandler(wrapper.ServerWrapper()),
		micro.WrapClient(wrapper.NewCliWrapper),
	)

	//注册邮件服务
	pb.RegisterMailServiceHandler(service.Service.Server(), handler.NewMailHandler(service))

	//接收命令参数，端口
	service.Service.Init()

	//解析服务Addr
	common.InitAddr(service)

	//初始rabbitmq连接池
	mq.InitRabbitmq()

	service.Service.Run()
}

